
# plot figures across multiple datasets
detector = 88
detector = 68
detector = 40
## detector = 35

plotList = plotList_Pb
plotList = plotList_Recent_Good
# plotList = plotList_CollimatorClosed

fig = plt.figure()
for ii in range(0,len(plotList)):
    pp = plotList[ii]
    plt.plot(dat[pp][:,detector], ls = lineStyles[ii/7], label = (filenameList[pp]+ ', ' + datasetDescription[pp] + ', ' + datasetTime[pp]))

plt.plot(np.array([0, 255, 255, 0, 0]), np.array([countRange[0], countRange[0], countRange[1], countRange[1], countRange[0]]))

plt.title('Detector #' + str(detector+1))
plt.legend()
plt.yscale('log')
plt.yscale('linear')
plt.xlabel('Bin', fontsize = 16)
plt.ylabel('Counts', fontsize = 16)
plt.grid()

# plot of rate spectrum with transmission correction

detector = 45
plotList = plotList_Pb_Good
transmissionCorrection = transmissionCorrectionPb_Good

##plotList = plotList_Fe_Good
##transmissionCorrection = transmissionCorrectionFe_Good
##
##plotList = plotList_Al
##transmissionCorrection = transmissionCorrectionAl


# plotList = plotList_CollimatorClosed

fig = plt.figure()
for ii in range(0,len(plotList)):
    pp = plotList[ii]
    x = dat[pp][:,detector]/datasetAcquisitionTime[pp]*transmissionCorrection[ii]
    plt.plot(x, ls = lineStyles[ii/7], label = (filenameList[pp]+ ', ' + datasetDescription[pp] + ', ' + datasetTime[pp]))

# plt.plot(np.array([0, 255, 255, 0, 0]), np.array([countRange[0], countRange[0], countRange[1], countRange[1], countRange[0]]))

plt.title('Detector #' + str(detector+1))
plt.legend()
plt.yscale('log')
plt.xlabel('Bin', fontsize = 16)
plt.ylabel('Rate', fontsize = 16)
plt.grid()



# plot gain shift variable as a function of detector

plotList = plotList_Pb
plotList = plotList_CollimatorClosed
plotList = plotList_Pb_5Inch_Good 

fig = plt.figure()
for ii in range(0,len(plotList)):
    pp = plotList[ii]
    plt.plot(np.arange(1,138), binMeanCollimatorClosed[pp,:]/binMeanCollimatorClosed[plotList[0],:], marker = markerTypes[ii], label = (filenameList[pp]+ ', ' + datasetDescription[pp] + ', ' + datasetTime[pp]))
plt.title('Gain Shift')
plt.legend(loc = 4)
plt.xlabel('Detector No.', fontsize = 16)
plt.ylabel('Gain Shift', fontsize = 16)
grid()


## plot gain shift versus time

detector = 88
##detector = 68
detector = 41

plotList = plotList_Pb_5Inch_Good 

fig = plt.figure()
plt.plot(datasetTimeNum[plotList] - datasetTimeNum[plotList[0]], binMeanCollimatorClosed[plotList,detector]/binMeanCollimatorClosed[plotList[0],detector], marker = markerTypes[ii], label = '')
plt.title('Gain Shift, Detector ' + str(detector))
plt.legend(loc = 4)
plt.xlabel('Time', fontsize = 16)
plt.ylabel('Gain Shift', fontsize = 16)
grid()



#  Plot of spectrum shape variables

detector =  45
plotList = plotList_Fe

fig = plt.figure()
cutt = plotList_Pb_Good
lab = 'Pb'
plt.plot(binMean[cutt,detector], binSTD[cutt,detector], marker = '*', markersize=12, label = lab)

cutt = plotList_Fe_Good
lab = 'Fe'
plt.plot(binMean[cutt,detector], binSTD[cutt,detector], marker = '*', markersize=12, label = lab)

cutt = plotList_Al_Good
lab = 'Al'
plt.plot(binMean[cutt,detector], binSTD[cutt,detector], marker = '*', markersize=12, label = lab)


plt.title('Detector #' + str(detector+1))
plt.legend(loc = 4)
# plt.yscale('log')
plt.ylabel('Distribution Standard Deviation', fontsize = 16)
plt.xlabel('Distribution Mean', fontsize = 16)
grid()



#  Plot of spectrum shape variables

detector =  93

plotList = plotList_Fe

fig = plt.figure()
cutt = plotList_Pb_Good
lab = 'Pb'
plt.plot(binMean[cutt,detector], quantileBins_75[cutt,detector] - quantileBins_25[cutt,detector], marker = '*', markersize=12, label = lab)

cutt = plotList_Fe_Good
lab = 'Fe'
plt.plot(binMean[cutt,detector], quantileBins_75[cutt,detector] - quantileBins_25[cutt,detector], marker = '*', markersize=12, label = lab)

cutt = plotList_Al_Good
lab = 'Al'
plt.plot(binMean[cutt,detector], quantileBins_75[cutt,detector] - quantileBins_25[cutt,detector], marker = '*', markersize=12, label = lab)


plt.title('Detector #' + str(detector+1))
plt.legend(loc = 4)
# plt.yscale('log')
plt.ylabel('Distribution Standard Deviation', fontsize = 16)
plt.xlabel('Distribution Mean', fontsize = 16)
grid()

#  Plot of discriminants
fig = plt.figure()

detectorList = goodDetectorsList.copy()
# detectorList = detectorList[0][1:50]
detectorList = detectorList[0][50:]

d1 = 1
d2 = 5
discList = (binSum, binMean, binSTD, binSTD/binMean, quantileBins_75 - quantileBins_25, (quantileBins_75 - quantileBins_25)/quantileBins_50, binMean - quantileBins_50)
discLabelList = ('Sum', 'Mean Bin','STD Bin', 'STD Bin/Mean Bin', 'Q75 - Q25', '(Q75 - Q25)/Q50', 'Mean Bin - Q50') 
disc1 = discList[d1]
disc2 = discList[d2]
xlabel = discLabelList[d1]
ylabel = discLabelList[d2]

labelList = 'Pb', 'Fe', 'Al'
cuttList = plotList_Pb_Good, plotList_Fe_Good, plotList_Al_Good

ii = 0

for ii in range(len(labelList)):  # cycle through list of materials
    cutt = cuttList[ii]
    lab = labelList[ii]
    temp1 = disc1[:,detectorList]
    temp2 = disc2[:,detectorList]
    kk = 0
    for jj in range(len(cutt)):  # cycle through list of datasets of that particular material type
        # plt.plot(temp1[cutt[kk],:], temp2[cutt[kk],:], marker = markerTypes[kk], markersize=12, label = datasetDescription[cutt[kk]], color = plotColors[ii])
        plt.scatter(temp1[cutt[kk],:], temp2[cutt[kk],:], marker = markerTypes[kk], s=15, color = plotColors[ii], label = datasetDescription[cutt[kk]])
        
        kk = kk + 1
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.title('Detector #' + str(detector+1))
plt.legend(loc = 4)
# plt.yscale('log')

